# -*-tcl-*- nowrap

This is one of four example files for the Dictionary Package for Alpha.
The other three files are
   man
   Country-codes
   Whisky-distillers

A dictionary file ideally has three sectors: The first sector is a header
with a description for human beings --- this is what you are reading now. 
The third sector is the main one: it is the raw data in alphabetical order. 
The second sector is a description for the Dictionary Programme, referred
to as the boot sector.  Here the programme learns how the file is
structured: how the alphabetical order is defined, and how the result 
should be presented on the screen.  As illustrated by the example 
'Whisky-distillers', the two first sectors are not mandatory, if just 
the file is in standard alphabetical order.  (In this case fallback 
definitions stand in.  These are defined in the file dictionary.tcl)

This example (which constitutes a dictionary of Tcl commands) illustrates
the use of an index file.  The main data file is 'Tcl 8.5 Commands.txt'
located in Help folder.  The file you are reading now is the index file:
every entry in the main sector has as its value a pair of integers, the
first being the position of the Tcl command in the data file, the second
being the number of bytes this entry occupies.  In this way the Dictionary
programme uses alphabetical order in this file to find the offset, and then
the format proc (which usually is meant just for formatting the return of
the lookup programme) takes a 'second round' reading the actual data from
the main file.  The advantage of using index file is that it can be faster
and more economical (no need to create a whole data file if the data
already exists elsewhere).  The disadvantage is that each time the main
data file changes, the index file must be recompiled.  (For this particular
case there is actually a mechanism which rebuilds the index if the data
file is newer.  The new index is placed in the Cache folder inside your
AlphaPrefs folder.

Another feature of this particular dictionary is that it specifies
proprietary window geometry for the dictionary console.  (Every dictionary
has its own consoleGeometry variable: you can save the current geometry in
the menu...)


<!-- BEGIN TCL

# This proc takes the first word of the input string
# strips all accents,
# and then removes all non-alpha letters
proc normalForm { chunk } {
  #just take the first word:
  regexp {[^ \t]+} $chunk chunk
  
  regsub -all {[áÁàÀâÂãÃåÅ]} $chunk {a} chunk
  regsub -all {[çÇ]} $chunk {c} chunk
  regsub -all {[éÉèÈêÊëË]} $chunk {e} chunk
  regsub -all {[íÍìÌîÎïÏ]} $chunk {i} chunk
  regsub -all {[ñÑ]} $chunk {n} chunk
  regsub -all {[óÓòÒôÔõÕøØöÖ]} $chunk {o} chunk
  regsub -all {[úÚùÙûÛüÜ]} $chunk {u} chunk
  regsub -all {[ÿŸ]} $chunk {y} chunk
  regsub -all {[æÆäÄ]} $chunk {ae} chunk
  regsub -all {[Œœ]} $chunk {oe} chunk

  regsub -all {[^A-Za-z_]} $chunk {} chunk
  return [string tolower $chunk]
}

# The raw output from the lookup proc consists in a command name,
# an offset and a size.  So go to the tcl-commands file and get this
# chunk:
proc formatOutput { linje } {
  global HOME
  if { ![regexp {([a-z_]+) (\d+) (\d+)$} $linje dummy headword offset size] } {
      return ""
  }
  variable currentHeadword $headword
  set ordstrom [open [file join $HOME Help "Tcl 8.5 Commands.txt"] r]
  seek $ordstrom $offset
  set res [read $ordstrom $size]
  close $ordstrom
  regsub -all "\n" $res "\r" res
  return $res
}


# Since the output format (given in "Tcl 8.5 Commands.txt") is a long 
# and narrow column, this dictionary has chosen to specify a matching
# window format.  It is computed from the screen dimensions.
# 
# Note: the name of the dictionary (which is chosen by the user, not by
# this file!) is always equal to the namespace tail of the dictionary,
# and when the boot sector is sourced we are in that namespace.  Hence
# we know:
set nameOfThisDictionary [namespace tail [namespace current]]
set consoleWidth 509
set consoleHeight [expr {$::screenHeight - 44}]
set leftOffset [expr {$::screenWidth - $consoleWidth}]
set bottomOffset 59

::console::create "* $nameOfThisDictionary *" -mode Text -minormode "dictionary" \
  -font [font::setSize $::defaultFont $::dictionarymodeVars(fontSize)] \
  -g [list $leftOffset $bottomOffset $consoleWidth $consoleHeight]

unset consoleWidth
unset consoleHeight
unset leftOffset
unset bottomOffset
unset nameOfThisDictionary

END TCL -->
  
after 124 5876
append 6080 1030
array 7190 8672
bgerror 15944 3975
binary 19999 33026
break 53105 1062
catch 54247 4249
cd 58576 863
chan 59519 41849
clock 101448 47059
concat 148587 1234
continue 149901 1080
dict 151061 15841
encoding 166982 4079
eof 171141 1518
error 172739 2176
eval 174995 2606
exec 177811 19244
exit 197135 1239
expr 198454 16066
fblocked 214841 2528
fconfigure 217449 14059
fcopy 231588 5982
file 237650 23316
fileevent 261046 5492
filename 266618 8366
flush 275099 1321
for 276500 2702
foreach 279282 3154
format 282516 10676
gets 293272 2317
glob 295669 8728
global 304477 1636
history 306193 4349
if 310622 2204
incr 312906 1342
info 314328 16757
interp 331165 44306
join 375551 901
lappend 376532 1185
lassign 377797 1710
lindex 379587 2499
linsert 382166 1366
list 383612 1205
llength 384897 1045
load 386022 7247
lrange 393349 1945
lrepeat 395374 914
lreplace 396368 2336
lreverse 398784 532
lsearch 399396 6645
lset 406121 4007
lsort 410208 7048
memory 417336 4792
msgcat 422208 12796
namespace 435084 38765
open 473929 21298
package 495307 15065
pid 510452 1332
proc 511864 3812
puts 515756 3286
pwd 519122 957
re_syntax 520159 26961
read 547200 3369
reflectedchan 550649 12454
regexp 563183 7336
registry 570599 8150
regsub 578829 5964
rename 584873 1224
return 586177 13070
scan 599327 12074
seek 611481 2712
set 614273 2277
socket 616630 8037
source 624747 1872
split 626699 2520
string 629299 18352
subst 647731 4500
switch 652311 6782
Tcl 659173 31135
tell 690388 1400
time 691868 867
trace 692815 21602
unknown 714497 4081
unload 718658 7307
unset 726045 2024
update 728149 2262
uplevel 730491 3768
upvar 734339 4646
variable 739065 3072
vwait 742217 2534
while 744831 2051

